package android_fields;

import static android_board.GUIBoard.FIELDHEIGHT;
import static android_board.GUIBoard.FIELDWIDTH;
import static android_board.GUIBoard.FONTSIZE;

import common.GUIColor;

import android.graphics.Typeface;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.widget.RelativeLayout;
import android_board.GUICenter;

public final class GUIChance extends AndroidField {
	private static final float TITLEHEIGHTPART = 0.79f;
//	private static final float SUBTEXTHEIGHTPART = 0.19f;
	
	public static class Builder extends AndroidField.Builder<GUIChance.Builder> implements
	iBuilder {
		public Builder() {
			this.title = "?";
			this.subText = "Prøv lykken";
			this.description = "Ta' et chancekort.";
			this.bgColor = new GUIColor(204, 204, 204);
		}

		@Override
		@SuppressWarnings("synthetic-access")
		public GUIChance build() {
			return new GUIChance(this.title, this.subText, this.description,
					this.bgColor, this.fgColor);
		}
		public Builder setTitle(String title) {
			this.title = title;
			return this;
		}

		public Builder setSubText(String subText) {
			this.subText = subText;
			return this;
		}

		public Builder setDescription(String description) {
			this.description = description;
			return this;
		}
	}

	private GUIChance(String title, String subText, String description,
			GUIColor bgColor, GUIColor fgColor) {
		super(bgColor, fgColor, title, subText, description);
		this.titleView.setText(this.title);
		this.titleView.setGravity(Gravity.CENTER);
		this.titleView.setTypeface(this.titleView.getTypeface(), Typeface.BOLD);
		int height = (int) (TITLEHEIGHTPART * FIELDHEIGHT);
		RelativeLayout.LayoutParams titleParams = new RelativeLayout.LayoutParams(FIELDWIDTH, height);
		this.subTextView.setText(this.subText);
		this.cell.addView(this.titleView, titleParams);
	}
	
	@Override
	public void setTitle(String title) {
		if (title.length() < 3)
			this.titleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, FONTSIZE + 28);
		else
			this.titleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, FONTSIZE);
		super.setTitle(title);
	}

	@Override
	public void displayOnCenter() {
		super.displayOnCenter();
		//        Center.label[1].setIcon(this.factory
		//                .createIcon("/pics/Prøv lykken small.png"));
		GUICenter.textViews[2].setText(this.description);
		GUICenter.textViews[2].setVisibility(View.VISIBLE);
		super.displayCarOnCenter();
	}
}
